<?php


   class OrderAction extends CommonAction{
   
   
   
   
     public function index(){
	   
	   
	  //session('openid','o96UCwSL6bu5MzS_R0IwYTqr2yi8');
		
		  
	   // $re=M('orderinfo')->where('openid="%s"',session('openid'))->order('id desc')->limit('2')->select();
		
		$w['openid']=array('eq',session('openid'));
		$re=$this->page('orderinfo',20,'id desc',$w);
		$i=-1;
		
		foreach($re as $v){
		
		   $i++;
		   
		   switch($v['type']){
		   
		   case "0": 
		   
		   $re[$i]['money']=$v['suijistart'];
		    
		   break;
		   
		   case "1":
		   
		   $re[$i]['money']=$v['gudingmoney'];
		   
		   break;
		   }
		   
		   
		   if($v['mohudu']!=""){
		     
			 $re[$i]['mohuzhi']=$v['mohudu'];
		   
		   }else{
		   
		     $sys=M('system')->where('id=1')->find();
		     $re[$i]['mohuzhi']=$sys['mohudu']*10;
		   
		   }
		   
		   
		   //这里来设置扫描数
		   
		   $saomiao=M('saomiao')->where('pid="%s"',$v['id'])->count();
		   $saomiao=($saomiao)?$saomiao:0;
		   $re[$i]['saomiao']=$saomiao;
		   
		   //支付金额
		   
		   $zw['status']=array('eq',1);
		   $zw['pid']=array('eq',$v['id']);
		   $zmoney=M('buyer')->where($zw)->select();
		   $zhifu=0;
		   
		   foreach($zmoney as $v){
		   
		     $zhifu+=$v['money'];
		   
		   }
		   
		   $re[$i]['zhifu']=$zhifu;
		   
		   
		   
		   	
		  $buyers=M('buyer')->where('pid="%s" and status=1',$v['id'])->select();
		
		  if($buyers!=null){
		    
			$re[$i]['isdashang']=1;
			
			$re[$i]['buyers']=$buyers;
		  
		  }else{
		  
		    $re[$i]['isdashang']=0;
		  }
		   
		  $w['pid']=array('eq',$v['id']);
		  
		  $zuiduo=M('buyer')->where($w)->order('money desc')->find();  
		  
		  $re[$i]['nicheng']=$zuiduo['nicheng'];
		  $re[$i]['touxiang']=$zuiduo['touxiang'];
		  $re[$i]['zmoney']=$zuiduo['money'];
		  $re[$i]['btime']=$zuido['btime'];
		   
		}
		
		
	
		
		$this->re=$re;
	
		
		
		
		//dump($this->re);
		
	    $this->display();
	 
	 }
	 
	 
	 
	 
	 public function down(){
	 
	    
	 
	 }
	 
	 
	 public function del(){
	 
	   $re=M('orderinfo')->where('id="%s"',$_POST['id'])->delete();
	   
	   $ajax=($re)?1:2;
	   
	   $this->ajaxReturn($ajax);
	 
	 }
	 
	 
	 public function xiangqing(){
	 
	    $re=M('buyer')->where('id="%s"',$_POST['id'])->find();
		
		$re['time']=date("Y-m-d H:i:s", $re['time']) ; 
		
		$this->ajaxReturn($re);
	 
	 }
	 
	 
	 
	 public function shezhi(){
	 
	 $re=M('orderinfo')->where('id="%s"',$_POST['id'])->find();
	 
	 if($re['type']==0){
	   
	   session('suiji',$re['suijistart']);
	   session('guding','');
	 }else{
	   session('suiji','');
	   session('guding',$re['gudingmoney']);
	 
	 }
	 
 
	 $this->ajaxReturn($re);
	 
	 
	 }
   
   
   
   
   }